﻿using RimWorld;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;
using Verse;
using Verse.Sound;

namespace Miao.Stand
{
    public class Command_StandRadiusTargetSimple : Command_Target
    {
        public StandPawn standPawn;
        public bool showAttackRange;
        public override void GizmoUpdateOnMouseover()
        {
            base.GizmoUpdateOnMouseover();

            standPawn.DrawBehaviorRadiusRing();
        }
        public override void ProcessInput(Event ev)
        {
            SoundDefOf.Tick_Tiny.PlayOneShotOnCamera();
            //Find.Targeter.BeginTargeting(targetingParams, delegate (LocalTargetInfo target)
            //{
            //    action(target);
            //});

            Find.Targeter.BeginTargeting(targetingParams, delegate (LocalTargetInfo target)//找到瞄准目标
            {
                action(target);
            },
              delegate (LocalTargetInfo target)
              {
                  standPawn.DrawBehaviorRadiusRing();
                  if (showAttackRange) standPawn.DrawRangeRadiusRing();
                  if (target.IsValid)
                  {
                      GenDraw.DrawTargetHighlight(target);//不知道为什么在源代码里高亮选中物失效了，可能是绘制覆盖的原因。而正常的情况下绘制是在Verb中结算的
                  }
              }, standValidator
              );
        }
        private bool standValidator(LocalTargetInfo target)
        {
            if (showAttackRange)
            {
                return standPawn.HasBeghavior(target.Thing) || standPawn.HasRangeAttack(target.Thing);
            }
            else
            {
                return standPawn.HasBeghavior(target.Thing);
            }
        }
    }
}
